import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons';
import { ActionType, ProCard, ProColumns } from '@ant-design/pro-components';
import { ProTable, TableDropdown } from '@ant-design/pro-components';
import { Button, ConfigProvider, Dropdown, Space, Tag, message } from 'antd';
import { TyWesternMedicineItem, TableListPagination } from './data';
import { useRef, useState } from 'react';
import { reqTyWesternMedicineList, reqDeleteTyWesternMedicine } from '@/services/tywesternmedicine';

const TyWesternMedicineTable = ({}) => {
	const [open, setOpen] = useState(false);
	const [type, setType] = useState('table');
	const [isOpen, setIsOpen] = useState<boolean>(false);
	const [iscreated, setIscreated] = useState(true);
	const actionRef = useRef<any>();
	const PopconfirmTitle = `确认删除吗？此操作不可撤销 `;
	const [row, setRow] = useState<any>();
	const handleModal = (show: boolean, row: any = null) => {
		setRow(row);
		setIsOpen(show);
	}

	const handleDelete = async (id: number) => {
		const res = await reqDeleteTyWesternMedicine({ id })
		if (res?.resultCode === '00000000') {
			message.success(res?.message)
			actionRef?.current.reload()
		}
	}

	const handleCreate = () => {
		setIsOpen(true);setRow({});setIscreated(false);
	}


	const handleTableList = async (params: TableListPagination) => {
		Object.assign(params,{"pageNum":params.current});
		const res = await reqTyWesternMedicineList(params);
		if (res?.resultCode === '00000000') {
			const { result, total } = res?.data;
			return {
				data: result,
				success: true,
				total: total,
			};
		}
	};

	const columns: ProColumns<TyWesternMedicineItem>[] = [
		{
			title: 'id',
			dataIndex: 'id',
			ellipsis: false,
			search: false
		},
		{
			title: 'name',
			dataIndex: 'name',
			ellipsis: false,
			search: false
		},
		{
			title: 'manufacturer',
			dataIndex: 'manufacturer',
			ellipsis: false,
			search: false
		},
		{
			title: 'sale_price',
			dataIndex: 'sale_price',
			ellipsis: false,
			search: false
		},
	];

	return (
		<ProCard>
			<ProTable<TyWesternMedicineItem>
				columns={columns}
				type={type as 'table'}
				search={false}
				actionRef={actionRef}
				request={(params): Promise<any> => handleTableList(params)}
				pagination={{pageSize: 10,}}
				rowKey="id"
				dateFormatter="string"
				headerTitle=""
				toolBarRender={() => [
					<Button key="3" type="primary" onClick={handleCreate}><PlusOutlined />
						新建
					</Button>
					]}
				/>
				{
				}
		</ProCard>
	)
}

export default TyWesternMedicineTable;

